//
//  MSLoginView.m
//  觅尚
//
//  Created by No.8 on 2019/3/19.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSLoginView.h"

@implementation MSLoginView
/** 登录标题*/
- (UILabel *)logintitle {
    if (!_logintitle) {
        _logintitle = [[UILabel alloc] init];
        _logintitle.frame = CGRectMake(150 * px, 300 * px, 150 * px, 70 * px);
        _logintitle.text  = @"登录";
        _logintitle.textColor = [UIColor whiteColor];
        _logintitle.font = [UIFont boldSystemFontOfSize:SYRealValue(38 / 2)];
        [self addSubview:_logintitle];
        
    }
    return _logintitle;
}

/** 手机号输入框*/
- (UITextField *)iphoneTextField{
    if (!_iphoneTextField) {
        _iphoneTextField = [[UITextField alloc] init];
        _iphoneTextField.frame = CGRectMake(self.logintitle.x, CGRectGetMaxY(_logintitle.frame) + 200 * px, (ScreenWidth - _logintitle.x * 2) / 1.5, 150 * px);
        _iphoneTextField.placeholder = @"请输入手机号";
         [_iphoneTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [_iphoneTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        _iphoneTextField.keyboardType = UIKeyboardTypeNumberPad;
        _iphoneTextField.textColor = [UIColor whiteColor];
        [self addSubview:_iphoneTextField];
        
    }
    return _iphoneTextField;
    
}

/** 获取验证码按钮*/
- (UIButton *)codeButton {
    if (!_codeButton) {
        _codeButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_iphoneTextField.frame), _iphoneTextField.y, _iphoneTextField.width * 0.5, _iphoneTextField.height)];
        [_codeButton setTitle:@"获取验证码" forState:UIControlStateNormal];
//        _codeButton.backgroundColor = [UIColor redColor];
        _codeButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
        [_codeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [self addSubview:_codeButton];
    }
    return _codeButton;
}


/** 账号下划线*/
- (UIImageView *)iphonelineIMG {
    if (!_iphonelineIMG) {
        _iphonelineIMG = [[UIImageView alloc] initWithFrame:CGRectMake(_iphoneTextField.x, CGRectGetMaxY(_iphoneTextField.frame), ScreenWidth - _logintitle.x * 2, 1)];
        _iphonelineIMG.image = [UIImage imageNamed:@"line"];
        [self addSubview:_iphonelineIMG];
        
    }
    return _iphonelineIMG;
}

/** 验证码输入框*/
- (UITextField *)codeTextField{
    if (!_codeTextField) {
        _codeTextField = [[UITextField alloc] init];
        _codeTextField.frame = CGRectMake(self.logintitle.x, CGRectGetMaxY(_iphonelineIMG.frame) + 80 * px, _iphonelineIMG.width, _iphoneTextField.height);
        _codeTextField.placeholder = @"请输入验证码";
        _codeTextField.keyboardType = UIKeyboardTypeNumberPad;
        [_codeTextField setValue:[UIColor grayColor] forKeyPath:@"_placeholderLabel.textColor"];
        [_codeTextField setValue:[UIFont systemFontOfSize:SYRealValue(35 / 2)] forKeyPath:@"_placeholderLabel.font"];
        _codeTextField.textColor = [UIColor whiteColor];
        [self addSubview:_codeTextField];
        
    }
    return _codeTextField;
    
}





/** 密码下划线*/
- (UIImageView *)passworldlineIMG {
    if (!_passworldlineIMG) {
        _passworldlineIMG = [[UIImageView alloc] initWithFrame:CGRectMake(_iphoneTextField.x, CGRectGetMaxY(_codeTextField.frame), _iphonelineIMG.width, _iphonelineIMG.height)];
        _passworldlineIMG.image = [UIImage imageNamed:@"line"];
        [self addSubview:_passworldlineIMG];
        
    }
    return _passworldlineIMG;
}


/** 登录按钮*/
- (UIButton *)loginButton {
    if (!_loginButton) {
        _loginButton = [[UIButton alloc] initWithFrame:CGRectMake(_iphoneTextField.x, CGRectGetMaxY(_passworldlineIMG.frame) + 120 * px, _iphonelineIMG.width, 120 * px)];
        _loginButton.layer.cornerRadius = _loginButton.height * 0.5;
        //        _loginButton.backgroundColor = [UIColor whiteColor];
        [_loginButton setTitle:@"登录" forState:UIControlStateNormal];
        //        _loginButton.frame = CGRectMake(10, 50, 200, 44);
        
        CAGradientLayer *gradientLayer =  [CAGradientLayer layer];
        gradientLayer.frame = _loginButton.bounds;
        gradientLayer.cornerRadius = _loginButton.height * 0.5;
        gradientLayer.startPoint = CGPointMake(0, 0);
        //        gradientLayer
        gradientLayer.endPoint = CGPointMake(1, 0);
        gradientLayer.locations = @[@(0.2),@(1.0)];//渐变点
        [gradientLayer setColors:@[(id)[WYCRGBColor(96, 59, 152) CGColor],(id)[WYCRGBColor(202, 72, 114) CGColor]]];//渐变数组
        [_loginButton.layer addSublayer:gradientLayer];
        _loginButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(36 / 2)];
        [self addSubview:_loginButton];
        
    }
    return _loginButton;
}

/** 账号密码登录*/
- (UIButton *)choseButton {
    if (!_choseButton) {
        _choseButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth * 0.33, CGRectGetMaxY(_loginButton.frame) + 40 * px, ScreenWidth * 0.33, 100 * px)];
        _choseButton.layer.cornerRadius = _iphoneTextField.height * 0.5;
//        _choseButton.backgroundColor = [UIColor whiteColor];
        [_choseButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_choseButton setTitle:@"账号密码登录" forState:UIControlStateNormal];
        _choseButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _choseButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(33 / 2)];
        [self addSubview:_choseButton];
    }
    return _choseButton;
}

/** 注册账号*/
- (UIButton *)registerButton {
    if (!_registerButton) {
        
        
        _registerButton = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth / 4, CGRectGetMaxY(_choseButton.frame) + 400 * px, ScreenWidth * 0.5, 100 * px)];
        _registerButton.layer.cornerRadius = _iphoneTextField.height * 0.5;
        //        _choseButton.backgroundColor = [UIColor whiteColor];
        [_registerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_registerButton setTitle:@"没有账号？去注册" forState:UIControlStateNormal];
        _registerButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        _registerButton.titleLabel.font = [UIFont systemFontOfSize:SYRealValue(35 / 2)];
        
        
        NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:_registerButton.titleLabel.text];
        [_registerButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [str addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(5,3)];
        _registerButton.titleLabel.attributedText = str;
        [_registerButton setAttributedTitle:str forState:UIControlStateNormal];
        [self addSubview:_registerButton];
    }
    return _registerButton;
}





- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
//        self.backgroundColor = [UIColor ];
        [self CreateSubView];
    }
    return self;
}
- (void)CreateSubView{
    
    self.backgroundColor = [UIColor whiteColor];
    
//    [self logintitle];
    
}
@end
